package com.yunji.news.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunji.news.entity.AnnualEnrollmentInfo;
import com.yunji.news.mapper.AnnualEnrollmentInfoMapper;
import com.yunji.news.service.AnnualEnrollmentInfoService;
import org.springframework.stereotype.Service;

/**
 * 年度招生信息服务实现类
 *
 * @author yunji
 * @since 2025-11-27
 */
@Service
public class AnnualEnrollmentInfoServiceImpl extends ServiceImpl<AnnualEnrollmentInfoMapper, AnnualEnrollmentInfo> 
        implements AnnualEnrollmentInfoService {

    @Override
    public IPage<AnnualEnrollmentInfo> getPageWithSchoolInfo(Page<AnnualEnrollmentInfo> page, 
                                                             Integer year, 
                                                             String schoolName, 
                                                             Integer status) {
        
        LambdaQueryWrapper<AnnualEnrollmentInfo> wrapper = new LambdaQueryWrapper<AnnualEnrollmentInfo>()
                .eq(year != null, AnnualEnrollmentInfo::getYear, year)
                .eq(status != null, AnnualEnrollmentInfo::getStatus, status)
                .orderByAsc(AnnualEnrollmentInfo::getSortOrder)
                .orderByDesc(AnnualEnrollmentInfo::getCreatedAt);
        
        return this.page(page, wrapper);
    }
}